﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.JumpAssignedObject.CCoJumpAssignedObjectCmd
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using DnProcessSimulateCommands.JumpAssignedObject.Resources;
using System.Collections.ObjectModel;
using System.Windows.Forms;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Ui;


namespace DnProcessSimulateCommands.JumpAssignedObject;

public class CCoJumpAssignedObjectCmd : TxButtonCommand
{
  private CApJumpAssignedObjectEnabler _enabler = new CApJumpAssignedObjectEnabler();
  private TxObjectFlowLocationOperation _lastJumpedLocation;
  private TxTransformation _lastJumpedPosition;

  public virtual void Execute(object cmdParams)
  {
    ITxObject allItem = ((Collection<ITxObject>) TxApplication.ActiveSelection.GetAllItems())[0];
    TxObjectFlowLocationOperation objFlowLocationOperation = (TxObjectFlowLocationOperation) null;
    if (allItem is TxObjectFlowLocationOperation)
      objFlowLocationOperation = allItem as TxObjectFlowLocationOperation;
    else if (allItem is TxObjectFlowOperation)
      objFlowLocationOperation = CApJumpAssignedObjectApp.GetFirstLocation(allItem as TxObjectFlowOperation);
    if (!TxObjectFlowLocationOperation.op_Inequality(objFlowLocationOperation, (ITxObject) null) || !TxObjectFlowLocationOperation.op_Inequality(objFlowLocationOperation, (ITxObject) this._lastJumpedLocation) && ((ITxLocatableObject) objFlowLocationOperation).AbsoluteLocation.Equals((object) this._lastJumpedPosition))
      return;
    ITxLocatableObject operationSimulatedObject = CApJumpAssignedObjectApp.GetFlowOperationSimulatedObject(objFlowLocationOperation);
    TxTransformation operationGripFrame = CApJumpAssignedObjectApp.GetFlowOperationGripFrame(objFlowLocationOperation);
    if (operationSimulatedObject == null || !TxTransformation.op_Inequality(operationGripFrame, (TxTransformation) null))
      return;
    Cursor current = Cursor.Current;
    Cursor.Current = Cursors.WaitCursor;
    TxApplication.ActiveUndoManager.StartTransaction();
    CApJumpAssignedObjectApp.MoveSimulatedObject(operationSimulatedObject, operationGripFrame, objFlowLocationOperation.AbsoluteLocation);
    this._lastJumpedLocation = objFlowLocationOperation;
    this._lastJumpedPosition = ((ITxLocatableObject) objFlowLocationOperation).AbsoluteLocation;
    TxApplication.RefreshDisplay();
    TxApplication.ActiveUndoManager.EndTransaction();
    Cursor.Current = current;
  }

  public virtual string Name => JumpAssignedObjectResources.JAO_CMD_NAME;

  public virtual string Tooltip => JumpAssignedObjectResources.JAO_CMD_TOOLTIP;

  public virtual string Description => JumpAssignedObjectResources.JAO_CMD_DESCRIPTION;

  public virtual string Category => JumpAssignedObjectResources.JAO_CMD_CATEGORY;

  public virtual string Bitmap => "JumpAssignedObject.Resources.jumpassignedobject.bmp";

  public virtual string LargeBitmap => "JumpAssignedObject.Resources.jumpassignedobject.png";

  public virtual ITxCommandEnabler CommandEnabler => (ITxCommandEnabler) this._enabler;

  public virtual ITxImage Image => (ITxImage) TxImageManager.GetImageByKey("JumpAssignedObject");
}
